# Copyright 2017 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

LOCAL_DIR := $(GET_LOCAL_DIR)

BUILDGEN_DIR=$(BUILDDIR)/system/host/fidl

MODULE := $(LOCAL_DIR)

MODULE_TYPE := hostlib

MODULE_COMPILEFLAGS := -O0 -g

MODULE_SRCS := \
    $(LOCAL_DIR)/lib/attributes.cpp \
    $(LOCAL_DIR)/lib/c_generator.cpp \
    $(LOCAL_DIR)/lib/error_reporter.cpp \
    $(LOCAL_DIR)/lib/flat_ast.cpp \
    $(LOCAL_DIR)/lib/formatter.cpp \
    $(LOCAL_DIR)/lib/json_generator.cpp \
    $(LOCAL_DIR)/lib/lexer.cpp \
    $(LOCAL_DIR)/lib/library_zx.cpp \
    $(LOCAL_DIR)/lib/names.cpp \
    $(LOCAL_DIR)/lib/parser.cpp \
    $(LOCAL_DIR)/lib/raw_ast.cpp \
    $(LOCAL_DIR)/lib/source_file.cpp \
    $(LOCAL_DIR)/lib/source_location.cpp \
    $(LOCAL_DIR)/lib/source_manager.cpp \
    $(LOCAL_DIR)/lib/tables_generator.cpp \
    $(LOCAL_DIR)/lib/tree_visitor.cpp \
    $(BUILDGEN_DIR)/lib/json_schema.cpp \

$(BUILDGEN_DIR)/lib/json_schema.cpp: $(LOCAL_DIR)/schema.json
	@$(MKDIR)
	$(NOECHO)rm -rf $@ && \
	printf "\
#include <string>\n\
#include \"fidl/json_schema.h\"\n\
// Autogenerated: Do not modify!\n\
std::string JsonSchema::schema_ = " >> $@ && \
	for i in $^; do \
	  printf "R\"JSON(""$$(cat $${i} | sed -e 's,\\,\\\\,g' )"")JSON\"" >> $@; \
	done &&  \
	printf "\
;\n" >> $@ \

include make/module.mk
